﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace Microsoft.SocialRecipes
{
    /// <summary>
    /// Column for HTML5 Video Player
    /// </summary>
    public class SPFieldHTML5VideoPlayer : SPFieldMultiColumn
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="SPFieldHTML5VideoPlayer"/> class.
        /// </summary>
        /// <param name="fields">The fields.</param>
        /// <param name="fieldName">Name of the field.</param>
        public SPFieldHTML5VideoPlayer(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SPFieldHTML5VideoPlayer"/> class.
        /// </summary>
        /// <param name="fields">An <see cref="T:Microsoft.SharePoint.SPFieldCollection"/> object that represents the fields.</param>
        /// <param name="typeName">A string that specifies the type name of the field.</param>
        /// <param name="displayName">A string that specifies the display name of the field.</param>
        public SPFieldHTML5VideoPlayer(SPFieldCollection fields, string typeName, string displayName)
            : base(fields, typeName, displayName)
        { }

        /// <summary>
        /// Gets the field type control that is used to render the field in Display, Edit, and New forms, as well as in data form Web Parts or pages that use field controls.
        /// </summary>
        /// <returns>A <see cref="T:Microsoft.SharePoint.WebControls.BaseFieldControl"/> object that represents the control.</returns>
        public override BaseFieldControl FieldRenderingControl
        {
            get
            {
                return new HTML5VideoFieldControl();
            }
        }

        /// <summary>
        /// Converts the specified field value into a field type value object.
        /// </summary>
        /// <param name="value">A string to convert into a field type value object.</param>
        /// <returns>
        /// An object that repesents the field type value object.
        /// </returns>
        public override object GetFieldValue(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                return new SPFieldHTML5VideoPlayerValue(value);
            }
            else
            {
                return null;
            }
        }

    }
}
